import sdljava.SDLException;
import sdljava.event.*;
import sdljava.video.SDLRect;


public class CharacterSprite extends Sprite{

	public CharacterSprite(GameWindow gameWindow, ImageData imageData, int x, int y, String imageFile) throws SDLException {
		super(gameWindow, imageData, x, y, imageFile);
	}
	
	public SDLRect spriteHandle(SDLEvent event){
		if(event.getType() == SDLEvent.SDL_KEYDOWN){
			int windowWidth = window.getGameSurface().getWidth();
			int windowHeight = window.getGameSurface().getHeight();
			switch (((SDLKeyboardEvent)event).getSym()){
				case SDLKey.SDLK_RIGHT: if(positionX + spriteImage.get(3).width < windowWidth){if(positionX + 40 + spriteImage.get(3).width > windowWidth){positionX = windowWidth-spriteImage.get(3).width;}else{positionX += 40;}}return spriteImage.get(3);
				case SDLKey.SDLK_LEFT: if(positionX-40 >= 0){positionX -= 40;}else{positionX = 0;} return spriteImage.get(4);
				case SDLKey.SDLK_UP: if(positionY-40 >= 0){positionY -= 40;}else{positionY = 0;} return spriteImage.get(2);
				case SDLKey.SDLK_DOWN: if(positionY + spriteImage.get(1).height < windowHeight){if(positionY + 40 + spriteImage.get(1).height > windowHeight){positionY = windowHeight-spriteImage.get(1).height;}else{positionY += 40;}}return spriteImage.get(1);
			}
		}
		return null;
	}
}
